<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>4-11 异步组件</title>
</head>
<body>
<div id="app">
    <suspense>
        <template #default>
            <async-component></async-component>
        </template>
        <template #fallback>
            <div>Loading...</div>
        </template>
    </suspense>

</div>
<script src="../lib/vue.global.js" type="text/javascript"></script>
<script>
    const { createApp, defineAsyncComponent } = Vue

    const asyncComponent = defineAsyncComponent(
        () => new Promise((resolve, reject) => {
          setTimeout(()=> {
            resolve({template: `<div>I am async component</div>`})
          }, 3000)
        })
    )

    const vm = createApp({
      data() {
        return {
          name: 'one'
        }
      },
      components: {
        'async-component': asyncComponent
      }
    }).mount('#app')
</script>
</body>
</html>
